<template>
	<view class="main">
		<view class="img-con">
			<!-- <image src="../../static/images/index_bg.jpg" mode="" class="img"></image> -->
			<!-- <image :src="contractInfo.qrcode" mode="" class="img"></image> -->
			<easy-loadimage :image-src="shareInfo.url" class="img" :open-transition="true"></easy-loadimage>
		</view>
		<view class="share">
			<!-- <view class="weixin">
				<image src="../../static/images/share_wx.png" mode=""></image>
				<text>发送给家长</text>
			</view> -->
			<view class="down" @click="downloadImage">
				<image src="../../static/images/share_dn.png" mode=""></image>
				<text>长按图片保存到相册</text>
			</view>
		</view>
		<!-- <view @click="navTo">返回签约列表</view> -->
	</view>
</template>

<script>
	import easyLoadimage from '../../components/easy-loadimage.vue'
	import { getShare } from '../../api/serviceApi.js'
	export default {
		data() {
			return {
				option: {},
				shareInfo: {}
			}
		},
		components: {
			easyLoadimage
		},
		onLoad(option) {
			this.option = option
			this._getShare()
		},
		methods: {
			async _getShare() {
				const params = {id: this.option.id}
				const res = await getShare(params)
				console.log(res)
				this.shareInfo = res.data.data
			},
			navTo() {
				uni.navigateTo({
					url: '../service/signListEmployee'
				})
			},
			downloadImage() {
				uni.downloadFile({
				    url: this.contractInfo.qrcode, //仅为示例，并非真实的资源
				    success: (res) => {
				        if (res.statusCode === 200) {
				            console.log('下载成功')
				            console.log(res)
							this.saveImg(res.tempFilePath)
				        }
				    }
				})
			},
			saveImg(tempFilePath) {
				let oA = document.createElement("a");
				oA.download = '我的二维码' // 设置下载的文件名，默认是'下载'
				oA.href = tempFilePath
				document.body.appendChild(oA)
				oA.click()
				oA.remove() // 下载之后把创建的元素删除
				uni.showToast({
					title: '下载成功'
				})
			}
		},
	}
</script>

<style lang="scss">
	.main {
		height: 100vh;
		background: #666 url("../../static/images/share_bg.jpg") no-repeat fixed bottom center;
		background-size: 100%;
		.img-con {
			text-align: center;
			padding-top: 40rpx;
			.img {
				width: 640rpx;
				height: 960rpx;
				border-radius: 2rpx;
				margin: 0 auto;
			}
		}
		.share {
			display: flex;
			justify-content: center;
			margin-top: 32rpx;
			.weixin,.down {
				width: 50%;
				display: flex;
				align-items: center;
				flex-direction: column;
				image {
					width: 80rpx;
					height: 80rpx;
				}
				text {
					font-family: SourceHanSansCN-Regular;
					font-size: 22rpx;
					color: #fff;
					padding-top: 20rpx;
				}
			}
			.weixin {
				padding-left: 80rpx;
			}
			.down {
				// padding-right: 80rpx;
			}
		}
	}
</style>
